package java6681.task;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;

import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Junichiro
 * @description 提取单词表
 * @date 2021-04-05 20:13
 **/

public class Words6681Controller {

    @FXML
    private ListView<String> lvWords;

    @FXML
    private TextArea taWords;

    @FXML
    private Label lblCount;

    @FXML
    void buttonClick() {
        /*规则*/
        String s = "[a-zA-Z]+";
        /*创建集合*/
        TreeSet<String> list = new TreeSet<>();
        Pattern pattern= Pattern.compile(s);
        /*全部转换为小写*/
        Matcher ma=pattern.matcher(taWords.getText().toLowerCase());
        /*获取文本框内的文本*/
        ObservableList<String> items = lvWords.getItems();
        /*依次存入集合中*/
        while (ma.find()){
            list.add(ma.group());
        }
        /*显示有几个单词*/
        lblCount.setText("有"+list.size()+"个唯一的单词");
        /*显示在右边的ListView中*/
        for (String s1 : list) {
            items.add(s1);
        }
    }

}

